package com.lzx.iteam.engine.observer;

import android.content.Context;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.lzx.iteam.contactssearch.conversion.PersistWorker;

/**
 * Created by hfx_lk on 15-1-14.
 */
public class FreshContactObserver extends ContentObserver {

    private Context mContext;
    private Handler mHandler;
    private long limitTime = 0;
    public static boolean Once = true;
    private static String TAG = "FreshContactObserver";
    public static boolean LOCAL_SAVE = false;
    public static final int MSG_RESTORE = 100;
    public static boolean ENTRANCE_ONECE = false;

    public Handler mRetoreHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MSG_RESTORE:

                    break;
            }
        }
    };

    public FreshContactObserver(Context context, Handler handler) {
        super(handler);
        mContext = context;
        mHandler = handler;
    }

    @Override
    public void onChange(boolean selfChange) {
        super.onChange(selfChange);
        Log.d(TAG, "in freshcontactobserver _________________________");
        final PersistWorker worker = PersistWorker.getInstance(mContext);
        if(LOCAL_SAVE){
            Log.d(TAG, "value: local save");
            /*if(Once){
                Once = false;
                mRetoreHandler.sendEmptyMessageDelayed(MSG_RESTORE, 5000);
            }*/

        }else{
            if(ENTRANCE_ONECE)return;
            ENTRANCE_ONECE = true;
            Log.d(TAG, "value: not local save");
            new Thread(){
                @Override
                public void run() {
                    worker.getChangesList(true);
                }
            }.start();
        }


    }


    @Override
    public boolean deliverSelfNotifications() {
        return super.deliverSelfNotifications();
    }
}
